-- CALC_BOSS_ACTIVITY_BOX_BONUS

-- 计算活动BOSS宝箱的奖励
-- @param user       玩家对象
-- @param dungeonId  地牢id
-- @param element    地牢元素
-- @param layer      所在层
return function(user, dungeonId, element, layer)
    -- 获取配置的参数
    local args      = DungeonM.queryElement(element, "dbase");
    local randSeed  = DungeonM.getRandSeed("DUNGEON_ACTIVITY_BOSS_BOX");
    local amount    = args["amount"] or 1;
    local classId, elemId, bossId, rank;
    local arr;

    if dungeonId == nil then
        dungeonId = user.dbase:query("currentDungeon");
    end

    if args["is_artifact_chips"] == 1 then
        -- 神器碎片
        elemId  = DungeonBossM.query(dungeonId, "boss_elem");
        bossId  = DungeonM.queryElement(elemId, "dbase")["class_id"];
        arr     = MonsterM.query(bossId, "artifact_chips");
        classId = FormulaM.invoke("FETCH_BY_RAND", arr, randSeed);

        return { 1, classId, amount, };
    elseif args["is_food"] == 1 then
        -- 食材
        rank    = args["rank"];
        arr     = ItemM.getFoodMaterial(rank);
        classId = FormulaM.invoke("FETCH_BY_RAND", arr, randSeed);

        return { 1, classId, 1 };
    elseif args["is_alchemy"] == 1 then
        -- 炼金材料
        classId = args["class_id"];
        return { 1, classId, amount, };
    elseif args["is_money"] == 1 then
        local dungeonInfo = ActivityDungeonM.getActivityByDungeonId(dungeonId);
        local grade       = dungeonInfo["grade"];

        -- 不同的模式奖励系数不同
        if grade == ACTIVITY_GRADE_DIFFICULT then
            amount = randSeed % (1000 +1) + 2500;
        elseif grade == ACTIVITY_GRADE_NORMAL then
            amount = randSeed % (800 +1) + 1200;
        else
            amount = randSeed % (400 +1) + 600;
        end

        -- 金币
        return { 2, "money", amount, };
    else
        -- 保护
        return { 2, "money", 1, };
    end
end
